package com.zcm.springbootwebsocket.common;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zcm.springbootwebsocket.entity.ResultMessage;

public class MessageUtils {
    /**
     *
     * @param isSystemMessage 是否为系统消息
     * @param fromName 消息发送者
     * @param message 消息
     * @return
     * @author Zhang Dapao
     */
    public static String getMessage(boolean isSystemMessage,String fromName,Object message){

            ResultMessage result = new ResultMessage();
            result.setSystem(isSystemMessage);
            result.setMessage(message);
            if (fromName!=null){
                result.setFromName(fromName);
            }
            //把字符串转成json格式的字符串
//            ObjectMapper mapper = new ObjectMapper();
//            return mapper.writeValueAsString(result);
            return JSON.toJSONString(result);
    }
}
